home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / vidbasic.zip / VWINSAV.ASM < prev   
Assembly Source File  |  1990-11-29  |  12KB  |  283 lines

  1. ;«RM120»«TS8,16,24,32,40,48,56,64»
  2. ;Updated 11/20/90
  3.  
  4. ;============================================================================
  5. ;   Copyright (C) Copr. 1990 by Sidney J. Kelly
  6. ;           All Rights Reserved.
  7. ;           Sidney J. Kelly
  8. ;           150 Woodhaven Drive
  9. ;           Pittsburgh, PA 15228
  10. ;           home phone 412-561-0950 (7pm to 9:30pm EST)
  11. ;============================================================================
  12.  
  13.  
  14. DOSSEG
  15. .model medium, Basic
  16.  
  17. .data
  18.     ;external data so all video routines can access
  19.     EVEN
  20.     EXTRN  B$DVIDEOSEG:WORD
  21.     EXTRN  B$DVIDEOPORT:WORD
  22.     EXTRN  B$DVIDEOINSTL:BYTE
  23. .code
  24. INCLUDE NOWAIT.INC
  25. EXTRN    Get_Adapter:FAR
  26.  
  27. comment         |
  28. CalcOffSet_Save  macro
  29.                               ;;destroys AX,CX & BX
  30.                               ;;modifies SI
  31.             Mov   AX,CurrRow
  32.         Dec   AX          ;;change from 1-25 to 0-24
  33.         Mov   CL,160
  34.         Mul   CL          ;;multiply CurrRow by 160
  35.             Mov   BX,BegCol   ;;get starting column
  36.         Dec   BX          ;;change from 1-80 to 0-79
  37.         Shl   BX,1        ;;multiply (CurrRow-1) by 2
  38.             Add   AX,BX       ;;get offset
  39.             Mov   SI,AX       ;;move to source index
  40.          endm
  41.         |
  42.  
  43. CalcOffSet_Save    macro
  44.     ;; This is slightly slower in the abstract
  45.     ;; sense on a 80286.  Cannot observe the difference
  46.     ;; on a 8088 with a CGA because of delay waiting for retrace.
  47.     ;; Though if have an 8088 with MONO or VGA/EGA it is faster
  48.     ;;
  49.     ;; Input:     Nothing
  50.     ;; Output:    SI = Memory Offset
  51.     ;; Destroys:  CX,AX
  52.     ;; Macro is used because inline code speeds routine
  53.     ;;               ;8088 ;80286
  54.     Xor     CL, CL     ;3    ;2   ;; Clear CL
  55.     Mov     AX,CurrRow ;14   ;5   ;; get starting Row
  56.     Dec     AX         ;3    ;2   ;; change from 1-25 to 0-24
  57.     Mov     CH, AL     ;2    ;2   ;; CX = Row * 256
  58.     Shr     CX, 1      ;2    ;2   ;; CX = Row * 128
  59.     Mov     SI, CX     ;2    ;2   ;; Store in SI
  60.     Shr     SI, 1      ;2    ;2   ;; SI = Row * 64
  61.     Shr     SI, 1      ;2    ;2   ;; SI = Row * 32
  62.     Add     SI, CX     ;3    ;2   ;; SI = (Row * 128)+(Row * 32)={Row*160}
  63.     Xor     CH, CH     ;3    ;2   ;; Clear CH register
  64.     Mov     AX,BegCol  ;14   ;5   ;; get starting Column
  65.     Dec     AX         ;3    ;2   ;; change from 1-80 to 0-79
  66.     Mov     CL, AL     ;2    ;2   ;; CX = Columns
  67.     Shl     CX, 1      ;2    ;2   ;; Account for attribute
  68.     Add     SI, CX     ;3    ;2   ;; SI = (Row * 160) + (Col * 2)
  69.                ;--------
  70.     endm               ;60    ;36  ;; clocks
  71.  
  72.  
  73. comment         |
  74. CalcOffSet_Rest  macro
  75.                               ;;destroys AX,CX & BX
  76.                               ;;modifies DI
  77.             Mov   AX,CurrRow
  78.         Dec   AX          ;;change from 1-25 to 0-24
  79.         Mov   CL,160
  80.         Mul   CL          ;;multiply CurrRow by 160
  81.             Mov   BX,BegCol   ;;get starting column
  82.         Dec   BX          ;;change from 1-80 to 0-79
  83.         Shl   BX,1        ;;multiply (CurrRow-1) by 2
  84.             add   AX,BX       ;;get offset
  85.             Mov   DI,AX       ;;move to source index
  86.          endm
  87.         |
  88.  
  89. CalcOffSet_Rest    macro
  90.     ;; This is slightly slower in the abstract
  91.     ;; sense on a 80286.  Cannot observe the difference
  92.     ;; on a 8088 with a CGA because of delay waiting for retrace.
  93.     ;; Though if have an 8088 with MONO or VGA/EGA it is faster
  94.     ;;
  95.     ;; Input:     Nothing
  96.     ;; Output:    DI = Memory Offset
  97.     ;; Destroys:  CX,AX
  98.     ;; Macro is used because inline code speeds routine
  99.     ;;               ;8088 ;80286
  100.     Xor     CL, CL     ;3    ;2   ;; Clear CL
  101.     Mov     AX,CurrRow ;14   ;5   ;; get starting Row
  102.     Dec     AX         ;3    ;2   ;; change from 1-25 to 0-24
  103.     Mov     CH, AL     ;2    ;2   ;; CX = Row * 256
  104.     Shr     CX, 1      ;2    ;2   ;; CX = Row * 128
  105.     Mov     DI, CX     ;2    ;2   ;; Store in DI
  106.     Shr     DI, 1      ;2    ;2   ;; DI = Row * 64
  107.     Shr     DI, 1      ;2    ;2   ;; DI = Row * 32
  108.     Add     DI, CX     ;3    ;2   ;; DI = (Row * 128)+(Row * 32)={Row*160}
  109.     Xor     CH, CH     ;3    ;2   ;; Clear CH register
  110.     Mov     AX,BegCol  ;14   ;5   ;; get starting Column
  111.     Dec     AX         ;3    ;2   ;; change from 1-80 to 0-79
  112.     Mov     CL, AL     ;2    ;2   ;; CX = Columns
  113.     Shl     CX, 1      ;2    ;2   ;; Account for attribute
  114.     Add     DI, CX     ;3    ;2   ;; DI = (Row * 160) + (Col * 2)
  115.                ;--------
  116.     endm               ;60    ;36  ;; clocks
  117.  
  118.  
  119. COMMENT |
  120. ===============================================================================
  121.     WINDSAVE.ASM - saves a portion of the text screen in QuickBASIC
  122.  call from Quickbasic:
  123.  DECLARE SUB WINDSAVE(BYVAL ULR%, BYVAL ULC%, BYVAL LRR%, BYVAL LRC%,BYVAL SEGADD%, BYVAL OFFADR% )
  124.  CALL  WINDSAVE(ULR%,ULC%,LRR%,LRC%,VARSEG(STORAGE(0)),VARPTR(STORAGE(0)))
  125.  Description of parameters:
  126.     Because a rectangle can be described by two points, we us the following
  127.     data points:
  128.        ULR = Upper left row
  129.        UCL = Upper left column
  130.        LRR = Lower right row
  131.        LRC = Lower right column
  132.     Dimension storage array to handle size of display in bytes
  133.     E.g. 80*20 display would require an integer array of 1600
  134. ===============================================================================
  135.           |
  136.  
  137. .code
  138. EVEN
  139. CurrRow        DW    0           ;current CurrRow
  140. BegCol         DW    0           ;Starting Column
  141. Num_Cols       DW    0           ;words to copy per line
  142. EndingRow      DW    0           ;Ending Row
  143.  
  144. EVEN
  145. WINDSAVE PROC FAR BASIC USES DI DS SI, \
  146. ULR:PTR, ULC:PTR, LRR:PTR, LRC:PTR, SEGADD:PTR, OFFADD:PTR
  147.  
  148.         Assume    DS:@data
  149.  
  150.         Cmp   B$DVIDEOINSTL,1
  151.         JE    didit
  152.         Call  Get_Adapter      ;find information about display
  153. didit:
  154.         Mov   DX,B$DVIDEOPORT
  155.         Push  B$DVIDEOSEG       ;save the screen segment for later
  156.         Mov   BX,OFFADD        ;get the starting address of the storage array
  157.             Mov   DI,BX            ;and put it into DI
  158.             Mov   BX,SEGADD        ;get the segment for the array
  159.             Mov   ES,BX            ;and assign it to ES
  160.  
  161.             Mov   AX,ULC           ;get first column (BYVAL)
  162.             Mov   BegCol,AX
  163.             Mov   AX,LRC           ;get last column (BYVAL)
  164.             SUB   AX,BegCol        ;subtract first column from first column
  165.         Inc   AX               ;Add 1 to get number of columns to print
  166.             Mov   Num_Cols,AX      ;AX=# of words to copy per line
  167.             Mov   AX,LRR           ;get last line (BYVAL)
  168.             Mov   EndingRow,AX
  169.             Mov   AX,ULR           ;get first line (BYVAL)
  170.             Mov   CurrRow,AX
  171.             CalcOffSet_Save        ;calculate offset for line
  172.             Mov   CX,Num_Cols      ;load counter with words to copy
  173.             Pop   DS               ;retrieve the screen segment saved from BX
  174.                                    ; earlier
  175.                    ; have to set DS last because when we do
  176.                    ; we lose access to DGROUP and the stack
  177.             Cld                    ;all data moves below will be forward
  178. EVEN
  179. ShowNext:
  180.         OR    DL,DL            ;monochrome or EGA (is DL = 0)?
  181.             JZ    Mono             ;yes, skip over the retrace stuff
  182. EVEN
  183. CGA:
  184.         CLI                    ;prevent interrupts
  185.         Wait_CGA_Retrace       ;wait for CGA retrace MACRO
  186.         Movsw                  ;now get the word from the screen
  187.                    ;and put it in array
  188.         STI                    ;allow interrupts again
  189.         Loop  CGA              ;loop until done
  190.             Jmp   Short NextLine   ;skip over the mono routine
  191. Mono:
  192.             Rep   Movsw            ;move the data in one operation
  193. NextLine:
  194.             Mov   AX,EndingRow
  195.         CMP   AX,CurrRow       ;Are we done restoring window?
  196.         JE    Finis            ;Finis if complete
  197.         Inc   CurrRow          ;next line
  198.             CalcOffSet_Save        ;compute new offset address
  199.             Mov   CX,Num_Cols      ;set counter to number of words to copy
  200.             jmp   Short ShowNext   ;jump to print next line
  201. Finis:
  202.         Ret                    ;return skipping the passed parameters
  203.             Assume    DS:@data
  204. WINDSAVE    Endp
  205.  
  206. comment     |
  207. ===================